﻿@model PhoneBilling.Models.ExtMgtModel
@{
    ViewBag.Title = "部组管理";
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.async.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.edit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.sortable.js")"></script>
<link href="@Url.Content("~/Content/js/jquery.treeview.css")" rel="stylesheet" type="text/css" />
 <script type="text/javascript">
     function selectEmptyGroup() {
         $("span.file").removeClass("li-active");
         $("a.file").hide();

         $("span.folder").removeClass("li-active");
         $("span.folder#emptyGroup").addClass("li-active");
         $("a.folder").hide();

         var url = '@Url.Content("~/Manage/ExtensionMgt/")' + "null";
         var targetDiv = "#phoneList"
         $.get(url, null, function (result) {
             $(targetDiv).html(result);
         });
     }
     function selectDepartment(department) {
         $("span.file").removeClass("li-active");
         $("a.file").hide();

         $("span.folder").removeClass("li-active");
         $("span.folder#" + department).addClass("li-active");
         $("a.folder").hide();
         $("a.folder#" + department).show();
         var url = '@Url.Content("~/Manage/ExtensionMgt/")' + department;
         var targetDiv = "#phoneList"
         $.get(url, null, function (result) {
             $(targetDiv).html(result);
         });
     }
     function selectGroup(group) {
         $("span.folder").removeClass("li-active");
         $("a.folder").hide();

         $("span.file").removeClass("li-active");
         $("span.file#" + group).addClass("li-active");
         $("a.file").hide();
         $("a.file#" + group).show();
         var url = '@Url.Content("~/Manage/ExtensionMgt/")' + group;
         var targetDiv = "#phoneList"
         $.get(url, null, function (result) {
             $(targetDiv).html(result);
         });
     }
     $(document).ready(function () {
         $("#tree").treeview();
         $("a.folder").hide();
         $("a.file").hide();
     });
     function deptDel(id, name) {
         var r = confirm("确认删除部门：" + name + "吗？");
         if (r == true) {
             window.location.href = "/Manage/DepartmentDelete?id=" + id;
         }
         return false;
     }
     function groupDel(id, name) {
         var r = confirm("确认删除分组：" + name + "吗？");
         if (r == true) {
             window.location.href = "/Manage/GroupDelete?id=" + id;
         }
         return false;
     }
  </script>
 @if (Model.Message != null){<h2>@Model.Message</h2>}
<div class="col25">
    <p id="btn-create" class="box"><a href="/Manage/DepartmentEdit"><span>新增部门</span></a><span>   </span><a href="/Manage/DepartmentSort"><span>排序</span></a></p>
    <div class="input-text">
        @Html.LabelFor(m => m.ExtCounts)
        @Html.DisplayFor(m => m.ExtCounts)
        </div>
    <ul id="tree" class="treeview-gray">
     @{foreach (var department in Model.DepartmentList)
     {
        <li class="closed"><span class="folder" id="@department.ID" onclick="selectDepartment('@department.ID')">@department.名称</span> 
        <span>
        @Html.ActionLink("新增子分组", "GroupEdit", new { parentID = department.ID, parentType = "Department" }, new { @class = "folder" , id=department.ID })
        @Html.ActionLink("修改", "DepartmentEdit", new { id = department.ID }, new { @class = "folder", id = department.ID })
        <a href='javascript:' onclick="deptDel('@department.ID','@department.名称')" class ="folder" id='@department.ID'>删除</a>
        @Html.ActionLink("排序", "GroupSort", new { id = department.ID,type="Department" }, new { @class = "folder", id = department.ID })
        </span>
        @if(department.分组List.Count >0)
        {
        <ul>
            @{foreach (var group1 in department.分组List)
              {
                <li class="closed"><span class="file" id="@group1.ID" onclick="selectGroup('@group1.ID')">@group1.名称</span> 
                @Html.ActionLink("新增子分组", "GroupEdit", new { parentID = group1.ID, parentType = "Group" }, new { @class = "file", id = group1.ID })
                @Html.ActionLink("修改", "GroupEdit", new { id = group1.ID }, new { @class = "file", id = group1.ID })
                <a href='javascript:' onclick="groupDel('@group1.ID','@group1.名称')" class = "file" id='@group1.ID'>删除</a>
                @Html.ActionLink("排序", "GroupSort", new { id = group1.ID, type = "Group" }, new { @class = "file", id = group1.ID })
                @Html.ActionLink("迁移", "GroupMotion", new { id = group1.ID }, new { @class = "file", id = group1.ID })
            
                @if (group1.分组List.Count > 0)
                {
                <ul>
                    @{foreach (var group2 in group1.分组List)
                      {
                        <li class="closed"><span class="file" id="@group2.ID" onclick="selectGroup('@group2.ID')">@group2.名称</span> 
                        @Html.ActionLink("新增子分组", "GroupEdit", new { parentID = group2.ID, parentType = "Group" }, new { @class = "file", id = group2.ID })
                        @Html.ActionLink("修改", "GroupEdit", new { id = group2.ID }, new { @class = "file", id = group2.ID })
                        <a href='javascript:' onclick="groupDel('@group2.ID','@group2.名称')" class = "file" id='@group2.ID'>删除</a>
                        @Html.ActionLink("排序", "GroupSort", new { id = group2.ID, type = "Group" }, new { @class = "file", id = group2.ID })
                        @Html.ActionLink("迁移", "GroupMotion", new { id = group2.ID }, new { @class = "file", id = group2.ID })
                
                        @if (group2.分组List.Count > 0)
                        {
                        <ul>
                            @{foreach (var group3 in group2.分组List)
                              {
                                <li><span class="file" id="@group3.ID" onclick="selectGroup('@group3.ID')">@group3.名称</span> 
                                @Html.ActionLink("修改", "GroupEdit", new { id = group3.ID }, new { @class = "file", id = group3.ID })
                                <a href='javascript:' onclick="groupDel('@group3.ID','@group3.名称')" class = "file" id='@group3.ID'>删除</a>
                                @Html.ActionLink("迁移", "GroupMotion", new { id = group3.ID }, new { @class = "file", id = group3.ID })
                                </li>
                              }}
                        </ul>
                        }
                
                        </li>
                      }}
                </ul>
                }
                </li>
              }}
        </ul>
        }
        
        </li>
     }}
     <li class="closed"><span class="folder" id="emptyGroup" onclick="selectEmptyGroup()">(未分组分机)</span></li>
     </ul>
</div>
<div class="col75">
    <div id="phoneList">
        <script type="text/javascript">
            function motion(groupID) {
                var str = "";
                $(".account").each(function () {
                    if ($(this).attr("checked") == "checked") {
                        if (str == "")
                            str += $(this).attr("id");
                        else
                            str += "!" + $(this).attr("id");
                    }
                });

                window.location.href = "/Manage/ExtensionMotion?selectedItem=" + str + "&groupID=" + groupID;
            }
            function c1() {
                if ($(".c1").attr("checked") == "checked") {
                    $(".account").attr("checked", "checked");
                }
                else {
                    $(".account").removeAttr("checked");
                }
            }
            function del(id, name) {
                var r = confirm("确认删除分机：" + name + "吗？");
                if (r == true) {
                    window.location.href = "/Manage/ExtensionDelete?groupID=" + id + "&id=" + name;
                }
                return false;
            }
            function delb(id) {
                var str = "";
                var phone = "";
                $(".account").each(function () {
                    if ($(this).attr("checked") == "checked") {
                        phone += "\r\n" + $(this).attr("id");
                        if (str == "") {
                            str += $(this).attr("id");
                        }
                        else {
                            str += "!" + $(this).attr("id");
                        }
                    }
                });
                if (phone == "")
                    return;

                var r = confirm("确认删除下列分机吗？" + phone);
                if (r == true) {
                    window.location.href = "/Manage/ExtensionBatchDelete?phone=" + str + "&groupID=" + id;
                }
                return false;
            }
            function change() {
                var grade = $(".grade").val();

                if (grade != "") {
                    $(".ext").hide();
                    $(".E-" + grade).show();
                    $(".listCounts").text($(".E-" + grade).length);
                }
                else {
                    $(".ext").show();
                    $(".listCounts").text($(".ext").length);
                }
            }
</script>
<div class="input-text">
             @Html.LabelFor(m => m.Group)
             @if (Model.Group != null)
             {
             @Html.DisplayFor(m => m.Group)
             }
             else
             {
                 <label>(未分组分机)</label>
             }
        </div>
@if (Model.Group != null)
{
    <p id="btn-create" class="box"><input  type="checkbox" class="c1" onclick="c1()" checked="checked" /><label>全选</label>
    <span>    </span>@Html.ActionLink("新增分机", "ExtensionEdit", new { groupID = Model.GroupID })
    @if(!Model.IsDept){<span>    </span>@Html.ActionLink("排序", "ExtensionSort", new { id = Model.GroupID })}
    <span>    </span><a href=# onclick="delb('@Model.GroupID')"><span>删除</span></a>
    <span>    </span><a href=# onclick="motion('@Model.GroupID')"><span>迁移</span></a></p>
}
else
{
    <p id="btn-create" class="box"><input  type="checkbox" class="c1" onclick="c1()" checked="checked" /><label>全选</label>
    <span>    </span><a href=# onclick="delb('@Model.GroupID')"><span>删除</span></a>
    <span>    </span><a href=# onclick="motion('@Model.GroupID')"><span>迁移</span></a></p>
}
@Html.HiddenFor(m => m.SelectItem, new { id = "SelectItem" })
<p id="btn-create" class="box"><label>分机数：</label><label class="listCounts">@Model.ExtensionList.Count</label><span>    </span>@Html.LabelFor(m => m.收费等级) @Html.DropDownListFor(m => m.收费等级, new SelectList(Model.GradeList, "ID", "Name"), new { style = "input-text", onchange = "change()", @class = "grade" })</p>
@{
    var grid = new WebGrid(source: Model.ExtensionList, canPage: false);
}
<table>
    <tr>
        <th>选择</th>
        <th>分机号码</th>
        <th>分组</th>
        <th>用户名</th>
        <th>地址</th>
        <th>收费等级</th>
        <th>费率</th>
        <th>收费话类</th>
        <th></th>
        <th></th>
        <th></th>
    </tr>
    @{
        foreach (var detail in Model.ExtensionList)
        {
        <tr class="ext E-@detail.收费等级">
            <td>@Html.CheckBox("选择", true, new { id = @detail.分机号码, @class = "account" })</td>
            <td>@detail.分机号码</td>
            <td>@detail.分组</td>
            <td>@detail.用户名</td>
            <td>@detail.地址</td>
            <td>@detail.收费等级</td>
            <td>@detail.费率</td>
            <td>@detail.收费话类</td>
            <td>@Html.ActionLink("修改", "ExtensionEdit", new { id = detail.分机号码, groupID = Model.GroupID })</td>
            <td>@Html.ActionLink("迁移", "ExtensionMotion", new { selectedItem = detail.分机号码, groupID = Model.GroupID })</td>
            <td>@Html.Raw(string.Format("<a href='javascript:' onclick=\"del('{0}','{1}')\">删除</a>", Model.GroupID, detail.分机号码))</td>
        </tr>
        }
    }
</table>
    </div>
</div>



